﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Lucky_bgy
{
    public partial class FormWinner : Form
    {
        public FormWinner()
        {
            InitializeComponent();
        }

        DBHelper helper = new DBHelper();

        private void button1_Click(object sender, EventArgs e)
        {
            int index = dataGridView1.CurrentRow.Index;
            if (index > -1)
            {
                String tempStr = dataGridView1.Rows[index].Cells["id"].Value.ToString();

                helper.ExecuteNonQuery("delete from bs_winner where ID=" + tempStr, null);

                fillTable();
                MessageBox.Show("删除成功");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void FormWinner_Load(object sender, EventArgs e)
        {
            fillTable();
        }

        private void fillTable()
        {
            DataTable dt = helper.ExecuteDataTable("select a.id , c.prize_name as 奖项,c.prize as 奖品,b.tel as 电话,b.user_name  as 姓名  from bs_winner a ,bs_user b ,bs_prize c where c.id = a.prize_id and a.tel = b.tel and a.valid_flag=1", null);
            if (dt.Rows.Count > 0)
            {
                dataGridView1.DataSource = dt;
                dataGridView1.Columns["ID"].Visible = false;
            }
            else
            {
                dataGridView1.DataSource = null;
            }
            button1.Enabled = false;
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            button1.Enabled = true;
        }
    }
}
